#include "StartState.h"
#include "base\Engine.h"
#include "game\World.h"
#include "..\..\SimpleHighscoreService.h"
#include "nodes\TextNode.h"

bool StartState::onActivation() {
	ds::WorldLayer wl = gEngine->getWorld().getLayerByName("StartScreen");
	gEngine->getWorld().activateLayer(wl);
	gEngine->getActionManager().startAction("MainMenu");
	return true;
}

bool StartState::onDeactivation() {
	ds::WorldLayer wl = gEngine->getWorld().getLayerByName("StartScreen");
	gEngine->getWorld().deactivateLayer(wl);
	gEngine->getActionManager().stopAction("MainMenu");
	gEngine->getActionManager().stopAction("CreditsMenu");
	return true;
}

void StartState::toogleActions(const char* activateName,const char* decactivateName) {
	gEngine->getActionManager().stopAction(decactivateName);
	gEngine->getActionManager().startAction(activateName);
}

void StartState::process(ds::EventBuffer& buffer) {
	if ( buffer.containsID(102)) {
		gEngine->activateGameState("Run");
	}
	else if ( buffer.containsID(104)) {
		toogleActions("CreditsMenu","MainMenu");
	}
	else if ( buffer.containsID(106)) {
		toogleActions("ScoreMenu","MainMenu");
	}
	else if ( buffer.containsID(107)) {
		toogleActions("MainMenu","HowtoPlayMenu");
	}
	else if ( buffer.containsID(105)) {
		toogleActions("HowtoPlayMenu","MainMenu");
	}
	else if ( buffer.containsID(111)) {
		toogleActions("MainMenu","ScoreMenu");
	}
	else if ( buffer.containsID(112)) {
		toogleActions("MainMenu","CreditsMenu");
	}
	else if ( buffer.containsID(103)) {
		gEngine->shutdown();
	}
}
